package com.rose.doorto.footbathdoor.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rose.doorto.footbathdoor.mapper.TeacherMapper;
import com.rose.doorto.footbathdoor.pojo.Teacher;
import com.rose.doorto.footbathdoor.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lqc
 * @since 2024-07-22
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    /**
     * 技师信息注册
     * @param teacher
     * @return
     */
    @Override
    public int addITeacher(Teacher teacher) {
        return teacherMapper.addITeacher(teacher);
    }

    /**
     * 技师信息修改
     * @param teacher
     * @return
     */
    @Override
    public int updateITeacher(Teacher teacher) {
        return teacherMapper.updateITeacher(teacher);
    }

    /**
     * 按照人气值进行排序
     * @return
     */
    @Override
    public List<Teacher> orderByScore() {
        return teacherMapper.orderByScore();
    }

    /**
     * 按照距离进行排序
     * @return
     */
    @Override
    public List<Teacher> orderByDistance() {
        List<Teacher> distance = teacherMapper.orderByDistance();
        return distance;
    }

    /**
     * 根据项目id获取技师信息列表
     * @param tid
     * @return
     */
    @Override
    public List<Teacher> getTeacherByProjectId(int tid) {
        List<Teacher> teacher = teacherMapper.getTeacherByProjectId(tid);
        if (teacher!=null){
            return teacher;
        }else {
            return null;
        }

    }

    /**
     * 条件查询分页
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public IPage<Teacher> getEntitiesByConditions(int pageNum, int pageSize, String name,int id) {
        Page<Teacher> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        if (name != null) {
            queryWrapper.like("name", name);
        }
//        if (id != null) {
//            queryWrapper.eq("id", id);
//        }
        // 这里可以添加更多的条件
        Page<Teacher> teacherPage = teacherMapper.selectPage(page, queryWrapper);
        return teacherPage;
    }

//    @Override
//    public Teacher selectById(Integer tid) {
//        return teacherMapper.selectById(tid);
//    }
}
